package com.higgins.lawapp.client.settings.presenter;

import com.google.gwt.user.client.ui.TabPanel;
import com.higgins.lawapp.client.listeners.DataSourceDTOListBoxListener;
import com.higgins.lawapp.client.settings.dataModel.DataSourceDTO;
import com.higgins.lawapp.client.settings.model.DataSourceModel;
import com.higgins.lawapp.client.settings.panels.FieldPanel;


public class DataSourceTabPanelPresenter  implements DataSourceDTOListBoxListener	{
	private DataSourceModel dataSourceModel = new DataSourceModel();
	private DataSourcePresenter dataSourcePresenter = new DataSourcePresenter(dataSourceModel);
	private TabPanel settingsTabPanelInternalTabs = new TabPanel();
	private int dataSourceSelectedIndex;
	
	public DataSourceTabPanelPresenter()	{
		dataSourceModel.setDataSourcePresenter(dataSourcePresenter);
	}
	
	public TabPanel getSettingsTabPanelInternalTabs()	{
		return settingsTabPanelInternalTabs;
	}
	
	private FieldPanel createDataSourcePanel(DataSourceDTO dataSourceDTOSelected)	{	
		dataSourcePresenter.clearPanel();
		if (dataSourceDTOSelected!=null)	{			
			dataSourcePresenter.createDataSourceField(dataSourceDTOSelected.getDataSourceName());
			dataSourcePresenter.createDataSourceURLField("");
		} 	else	{
			dataSourcePresenter.createDataSourceField("");
			dataSourcePresenter.createDataSourceURLField("");
		}
//		dataSourcePresenter.createButtons();
		return dataSourcePresenter.getDataSourcePanel();
	}

	@Override
	public void setDataSourceDTOSelected(DataSourceDTO dataSourceDTOSelected, int dataSourceSelectedIndex) {
		this.dataSourceSelectedIndex = dataSourceSelectedIndex;
		settingsTabPanelInternalTabs.clear();
		settingsTabPanelInternalTabs.add(createDataSourcePanel(dataSourceDTOSelected), "Top Level");
		settingsTabPanelInternalTabs.selectTab(0);
	}
}
